var tgd = tgd || {};
tgd.Simulations = tgd.Simulations || {};
tgd.Simulations.Zombies = tgd.Simulations.Zombies || {};

tgd.Simulations.Zombies.Brain = function (physics, vision) {

	var _p = physics;
	var _v = vision;

	/*if (tgd.Simulations.Zombies.Brain._initialized === undefined) {

		tgd.Simulations.Zombies.Brain.prototype.think = function() {
			return null;
		}

		tgd.Simulations.Zombies.Brain._initialized = true;
	}*/

	//if i want encapulation, I cannot add to prototype?
	// @return { Type, Position? : { X, Y } /* move */, Person /* attack */ }
	this.think = function() {
		var retVal = {};
		retVal.Position = {};

		var results = _v.getVision();
		var attackable = _p.getPeopleInAttackRange(this);

		//todo: playing
		if (results.some(function(a,b,c) { return a.Type === tgd.Simulations.Zombies.Enums.HumanType.Zombie; })) {
			retVal.Position.X = results[0].Position.X * -1;
			retVal.Position.Y = results[0].Position.Y * -1;
		} else if (attackable.some(function(a,b,c) { return true;/* a.Type !== tgd.Simulations.Zombies.Enums.HumanType.Zombie;*/ } )) {
			retVal.Person = attackable[0];
		} else if (results.length === 0) {
			var r1 = parseInt(Math.random() * 10) % 2 == 0
			var r2 = parseInt(Math.random() * 10) % 2 == 0;
			retVal.Position.X = (r1 ? 1 : -1);
			retVal.Position.Y = (r2 ? 1 : -1);
		} else {
			retVal.Position.X = retVal.Position.Y =  0;
		}

		retVal.Type = (typeof retVal.Position.X === "undefined" ? tgd.Simulations.Zombies.Enums.ActionType.Attack : tgd.Simulations.Zombies.Enums.ActionType.Move);
		if (typeof retVal.Position.X === "undefined") { retVal.Position = undefined; }

		return retVal;
	}

	if (typeof console != "undefined") { console.log("tgd.Simulations.Zombies.Brain created"); }
}
